package com.tangsm.spring.boot.validation.exception;

import com.tangsm.spring.boot.validation.enums.ResultStatus;

/**
 * 自定义异常
 * <p>约定所有异常信息都要注册到响应码枚举中</p>
 * @author tangsm
 */
public class BusinessException extends RuntimeException {

    /**
     * 响应码枚举
     */
    private final ResultStatus resultStatus;

    /**
     * 无参构造
     */
    public BusinessException() {
        super(ResultStatus.SERVER_ERROR.getMsg());
        this.resultStatus = ResultStatus.SERVER_ERROR;
    }

    /**
     * 根据响应码枚举构造对象
     * @param resultStatus 响应码枚举
     */
    public BusinessException(ResultStatus resultStatus) {
        super(resultStatus.getMsg());
        this.resultStatus = resultStatus;
    }

    public ResultStatus getResultStatus() {
        return resultStatus;
    }
}
